//
//  ReadViewController.m
//  Project_ZFR_MUSIC
//
//  Created by 张福润 on 16/2/24.
//  Copyright © 2016年 张福润. All rights reserved.
//

#import "ReadViewController.h"
#define GETURL @"http://api2.pianke.me/read/columns"
#define POSTURL @"http://api2.pianke.me/ting/radio"//@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}
@interface ReadViewController ()

@end

@implementation ReadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor cyanColor];
    

    
    
   
    [self get];
    
     //POST
    [self post];
    
    // Do any additional setup after loading the view.
}

-(void)post{
    NSURLSession *session=[NSURLSession sharedSession];
    //字符串装utf-8
    NSCharacterSet *set=[NSCharacterSet characterSetWithCharactersInString:POSTURL];
    NSString *urlString=[POSTURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    NSMutableURLRequest *requset=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置请求方式
    [requset setHTTPMethod:@"POST"];
    
    //@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}
    NSString *bodyStr =@"client=1&deviceid=63A94D37-33F9-40FF-9EBB-481182338873&auth=&version=3.0.2";
    
    NSData *data=[bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [requset setHTTPBody:data];
    
    
    NSURLSessionTask *task=[session dataTaskWithRequest:requset completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result=[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];
        NSLog(@"%@",result);
    }];
    
    [task resume];
}
-(void)get{
    //GET
    NSURLSession *session=[NSURLSession sharedSession];
    //字符串装utf-8
    NSCharacterSet *set=[NSCharacterSet characterSetWithCharactersInString:GETURL];
    NSString *urlString=[GETURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    NSMutableURLRequest *requset=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置请求方式
    [requset setHTTPMethod:@"GET"];
    NSURLSessionTask *task=[session dataTaskWithRequest:requset completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result=[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];
        NSLog(@"%@",result);
    }];
    
    [task resume];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
